package com.gzy.cbrsystem.core;

import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;

import com.gzy.cbrsystem.core.insomnia.InsomniaCaseDescription;
import com.gzy.cbrsystem.core.interfaces.SimilarityCalculation;
import com.gzy.cbrsystem.core.interfaces.VectorSimilarity;

public class VectorAverage implements VectorSimilarity {

	public double calculate(InsomniaCaseDescription ia,
			InsomniaCaseDescription ib, List<Field> atts,
			Map<Field, Double> weights, SimilarityCalculation attSim) {

		double sim=0;
		double weight=0;
		for(Field att:atts)
		{
			try {
				sim+=attSim.CalculateSimilarity(att.get(ia), att.get(ib));
				weight+=weights.get(att);
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}
		sim=sim/weight;
		return sim;
	}

}
